#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include<QResizeEvent>
#include<QProgressDialog>
#include<QMessageBox>
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
     ui->horizontalLayout->installEventFilter(this);
    playerVideo = new PlayerVideo(this);
    ui->horizontalLayout->setDirection(QBoxLayout::RightToLeft);
    ui->horizontalLayout->addWidget(playerVideo,Qt::AlignRight);
    videoCompress=new VideoCompress();
    compressForm = new CompressForm;


}

MainWindow::~MainWindow()
{
    delete ui;
    delete compressForm;
}

void MainWindow::changeEvent(QEvent *event)
{
    qDebug()<<"窗口改变触发";
    if(QEvent::WindowStateChange == event->type())
    {
        QWindowStateChangeEvent * stateEvent = dynamic_cast<QWindowStateChangeEvent*>(event);
        if(Q_NULLPTR != stateEvent)
        {
            if(this->isMinimized())
            {
                qDebug()<<"最小化";
            }
            else if(this->isMaximized())
            {
                qDebug()<<"最大化";
            }
            else if(this->windowState()==Qt::WindowNoState)
            {
                qDebug()<<"正常";
            }
        }
    }
}
void MainWindow::resizeEvent(QResizeEvent *event){
    qDebug()<<"窗口自定义改变触发";
    qDebug()<< event->type();
    if(QEvent::Resize == event->type())
    {
        QResizeEvent *e = (QResizeEvent*)event;
           qDebug()<<e;
         int w = e->size().width();
         int h = e->size().height();
         int vw=w-10;
         int vh=h-80;
         ui->horizontalLayoutWidget->move(10,10);
         ui->horizontalLayoutWidget->resize(vw-10, vh);

         ui->pushButton_2->move(w/2,vh+20);

    }
}



void MainWindow::on_pushButton_2_clicked()
{


   QString filePath = playerVideo->getFilePath();
//    std::string dstPath = "C:/Users/Administrator/Desktop/xuan/2222.mp4";
//     Transcode transcode(filePath,dstPath,720,480,2000000);

//    ///创建一个线程专门用来解码视频
//    std::thread([&]( Transcode transcode)
//    {
//        transcode.doTranscode();
//    }, transcode).detach();

    VideoInfo videoInfo = playerVideo->getVideoInfo();
     qDebug()<<videoInfo.fps;
    if(!videoInfo.isFill){
         QMessageBox::critical(NULL, "提示", QString("请先选择源文件"));
        compressForm->hide();
        return;
    }else{
        compressForm->init(videoInfo.rate,videoInfo.fps,videoInfo.width,videoInfo.height,filePath );
        compressForm->show();
    }


}
